package com.system.module.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.system.common.page.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.system.framework.aspectj.lang.annotation.Log;
import com.system.framework.aspectj.lang.enums.BusinessType;
import com.system.module.business.domain.ResourceCode;
import lombok.extern.slf4j.Slf4j;
import com.system.module.business.service.IResourceCodeService;
import com.system.framework.web.controller.BaseController;
import com.system.framework.web.domain.Result;
import com.system.common.utils.poi.ExcelUtil;

/**
 * 源码资源控制层
 *
 * @author mars
 * @date 2023-09-08
 */
@Slf4j
@AllArgsConstructor
@RestController
@Api(value = "源码资源接口管理",tags = "源码资源接口管理")
@RequestMapping("/app/code" )
public class ResourceCodeController extends BaseController {

    private final IResourceCodeService iResourceCodeService;

    /**
     * 查询源码资源列表
     */
    @ApiOperation(value = "查询源码资源列表")
    @PreAuthorize("@ss.hasPermi('app:code:list')")
    @GetMapping("/list")
    public PageInfo<ResourceCode> list(ResourceCode resourceCode) {
        return iResourceCodeService.findPageBySpec(resourceCode);
    }

    /**
     * 获取源码资源详细信息
     */
    @ApiOperation(value = "获取源码资源详细信息")
    @PreAuthorize("@ss.hasPermi('app:code:query')" )
    @GetMapping(value = "/query/{id}" )
    public Result getInfo(@PathVariable("id" ) Long id) {
        return Result.success(iResourceCodeService.getById(id));
    }

    /**
     * 新增源码资源
     */
    @ApiOperation(value = "新增源码资源")
    @PreAuthorize("@ss.hasPermi('app:code:add')" )
    @Log(title = "源码资源" , businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody ResourceCode resourceCode) {
        return Result.success("新增成功",iResourceCodeService.add(resourceCode));
    }

    /**
     * 修改源码资源
     */
    @ApiOperation(value = "修改源码资源")
    @PreAuthorize("@ss.hasPermi('app:code:edit')" )
    @Log(title = "源码资源" , businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public Result edit(@RequestBody ResourceCode resourceCode) {
        return toAjax(iResourceCodeService.update(resourceCode) ? 1 : 0);
    }

    /**
     * 删除源码资源
     */
    @ApiOperation(value = "删除源码资源")
    @PreAuthorize("@ss.hasPermi('app:code:remove')" )
    @Log(title = "源码资源" , businessType = BusinessType.DELETE)
    @DeleteMapping("/remove/{ids}" )
    public Result remove(@PathVariable Long[] ids) {
        return toAjax(iResourceCodeService.deleteBatch(Arrays.asList(ids)) ? 1 : 0);
    }

    /**
     * 导出源码资源列表
     */
    @ApiOperation(value = "导出源码资源列表")
    @PreAuthorize("@ss.hasPermi('app:code:export')" )
    @Log(title = "源码资源" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public Result export(ResourceCode resourceCode) {
        List<ResourceCode> list = iResourceCodeService.getList(resourceCode);
        ExcelUtil<ResourceCode> util = new ExcelUtil<ResourceCode>(ResourceCode. class);
        return util.exportExcel(list, "code" );
    }
}
